package com.gnerv.plug.note.action;

import com.gnerv.plug.note.dialog.CreateNoteDialog;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.editor.Editor;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

public class CreateNoteAction extends AnAction {

    public CreateNoteAction() {
        super();
    }

    public CreateNoteAction(String text, String description, Icon icon) {
        super(text, description, icon);
    }

    @Override
    public void actionPerformed(@NotNull AnActionEvent event) {
        final Editor editor = event.getRequiredData(CommonDataKeys.EDITOR);
        String selectedText = editor.getSelectionModel().getSelectedText();
        CreateNoteDialog createNoteDialog = new CreateNoteDialog();
        createNoteDialog.setNoteContent(selectedText);
        createNoteDialog.show();
    }

}
